<template>
  <div class="agency-wrap">
    <el-form class="form">
      <el-form-item label-width="100px" label="代理商姓名：">
        <el-input v-model="linkname" type="text"/>
      </el-form-item>
      <el-form-item label-width="120px" label="手机号：">
        <el-input v-model="phone" type="text"/>
      </el-form-item>
      <el-form-item label-width="100px" label="状态：">
        <el-select v-model="state" placeholder="请选择">
          <el-option
            v-for="item in states"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label-width="100px" label="发布城市：">
        <area-cascader v-model="city" :level="1" :data="pcaa" type="text" placeholder="请选择省/市/区" @change="hanleCheckCity"/>
      </el-form-item>
      <el-form-item label-width="50px">
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="index" label="序号" width="180"/>
      <el-table-column prop="areaname" label="代理城市" width="200"/>
      <el-table-column prop="username" label="代理商姓名" width="200"/>
      <el-table-column prop="phone" label="手机号" width="200"/>
      <el-table-column prop="optdate" label="申请时间" width="200"/>
      <el-table-column prop="authDate" sortable label="审核时间" width="200"/>
      <el-table-column prop="state" label="状态" width="220">
        <template slot-scope="scope">
          <el-tag :type="scope.row.state !== 3 ? 'success' : 'danger'">{{ scope.row.state === 1 ? '未审核': scope.row.state === 2 ? '审核通过': '审核未通过' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remarks" label="备注" min-width="200"/>
      <!-- <el-table-column prop="switch" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="danger" @click="handleDelete(scope)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <pagination v-show="total>10" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <el-dialog
      :visible.sync="centerDialogVisible"
      title="提示"
      width="30%"
      center>
      <span>确认删除？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import { pcaa } from 'area-data'
import { agencyCity } from '@/api/user'
export default {
  name: 'Publish',
  components: {
    Pagination
  },
  data() {
    return {
      agencyName: '',
      phone: '',
      statesValue: '',
      city: [],
      pcaa: pcaa,
      states: [
        {
          value: '',
          label: '全部'
        },
        {
          value: 1,
          label: '未审核'
        },
        {
          value: 2,
          label: '审核通过'
        },
        {
          value: 3,
          label: '审核未通过'
        }
      ],
      total: 0,
      listQuery: {
        page: 1,
        limit: 10
      },
      centerDialogVisible: false,
      state: '',
      iDisplayStart: 0,
      iDisplayLength: 10,
      linkname: '',
      areaname: '',
      list: []
    }
  },
  computed: {
    tableData() {
      const result = []
      this.list.map((item, index) => {
        // const idx = this.type.findIndex((subitem) => {
        //   return item.typecode === subitem.code
        // })
        const flag = item.state === 1
        item = Object.assign({}, item, { index: `${(this.listQuery.page - 1) * this.listQuery.limit + 1 + index}`, edit: false, leading: flag })
        result.push(item)
      })
      return result
    }
  },
  created() {
    this.getAgencyList()
  },
  methods: {
    handleDelete(scope) {
      this.centerDialogVisible = true
    },
    getList(prop) {
      this.listQuery.page = prop.page
      this.listQuery.limit = prop.limit
      this.iDisplayStart = (prop.page - 1) * prop.limit
      this.iDisplayLength = prop.limit
      this.getAgencyList()
    },
    hanleCheckCity() {
      const { city } = this
      if (city.length) {
        this.areaname = `${city[0]}${city[1]}${city[2]}`
      } else {
        this.areaname = ''
      }
    },
    getAgencyList() {
      const { state, iDisplayStart, iDisplayLength, linkname, areaname, phone } = this
      agencyCity({ state, iDisplayStart, iDisplayLength, linkname, areaname, phone })
        .then((res) => {
          console.log(res)
        }).catch((e) => {
          this.$message.error({
            message: '请稍后再试',
            duration: 1000
          })
        })
    },
    handleSearch() {
      this.getAgencyList()
    }
  }
}
</script>
<style lang="scss" scoped>
.agency-wrap {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  .form {
    display: flex;
    flex-wrap: wrap;
  }
  .switch-btn {
    margin-top: 20px;
    margin-bottom: 20px;
    margin-left: 20px;
  }
}
</style>
